package com.tfy.liquor.controller;

import com.tfy.liquor.bean.Result;
import com.tfy.liquor.bean.SystemConfiguration;
import com.tfy.liquor.service.SystemConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统配置参数
 */
@RestController
@RequestMapping("/systemConfiguration")
public class SystemConfigurationController {
    @Autowired
    private SystemConfigurationService systemConfigurationService;

    // 添加参数设置
    @RequestMapping("/addSystemConfiguration")
    public Result addSystemConfiguration(SystemConfiguration systemConfiguration) {
        if (null == systemConfiguration) {
            return new Result().bad_CodeIsNull();
        }
        if (systemConfigurationService.addSystemConfiguration(systemConfiguration)) {
            return new Result().ok("添加成功！");
        }
        return new Result().error("添加失败！");
    }

    // 获取系统参数信息
    @RequestMapping("/getSystemConfiguration")
    public Result getSystemConfiguration(Integer pageNum, Integer pageSize) {
        if (null == pageNum || null == pageSize) {
            // 返回参数错误
            return new Result().bad_CodeIsNull();
        }
        return new Result(systemConfigurationService.getSystemConfiguration(pageNum, pageSize)).ok();
    }

    // 修改使用状态
    @RequestMapping("/editSystemConfigurationStatus")
    public Result editSystemConfigurationStatus(SystemConfiguration systemConfiguration) {
        if (null == systemConfiguration) {
            return new Result().bad_CodeIsNull();
        }
        if (systemConfigurationService.editSystemConfigurationStatus(systemConfiguration)) {
            return new Result().ok("操作成功！");
        }
        return new Result().error("操作失败！");
    }
}
